package com.example.sqldemo;

import android.content.Context;

import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteOpenHelper;

/**
 * Created by : xiaoyehai
 * Create date : 2019/9/12 6:05
 * description :
 * <p>
 * SQLiteOpenHelper要引用sqlcipher包下的
 */
public class DBCipherHelper extends SQLiteOpenHelper {

    private static final String DB_NAME = "MedicalDB";//数据库名字
    public static final String DB_PWD = "zhu2003$$kao@163.com.xzfvd*";//数据库密码
    public static String TABLE_NAME = "person";// 表名
    public static String FIELD_ID = "_id";// 列名
    public static String FIELD_NAME = "name";// 列名
    private static final int DB_VERSION = 1;   // 数据库版本


    public DBCipherHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);

        //不可忽略的 进行so库加载
        SQLiteDatabase.loadLibs(context);
    }


    /**
     * 创建数据库
     *
     * @param db
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建表
        String sql = "CREATE TABLE " + TABLE_NAME + "(" + FIELD_ID + " integer primary key autoincrement , " + FIELD_NAME + " text not null);";
        db.execSQL(sql);

    }

    /**
     * 数据库升级
     *
     * @param db
     * @param oldVersion
     * @param newVersion
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}